package com.xianggu.designMode.combination.demo02.impl;

import com.xianggu.designMode.combination.demo02.Command;
import com.xianggu.designMode.combination.demo02.Graphic;

// 具体命令：旋转图形
public class RotateCommand implements Command {
    private Graphic graphic;
    private double angle;
    private double prevAngle;

    public RotateCommand(Graphic graphic, double angle) {
        this.graphic = graphic;
        this.angle = angle;
    }

    @Override
    public void execute() {
        prevAngle = graphic.getRotation();
        graphic.rotate(angle);
    }

    @Override
    public void undo() {
        graphic.setRotation(prevAngle);
    }
}
